﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.Reflection;

using GISforTT_API;

using ESRI.ArcGIS.Client;

namespace eGrid_App
{
    /// <summary>
    /// Interaction logic for My_Application.xaml
    /// </summary>
    public partial class My_Application : UserControl
    {
        private Window mainWindow;        
        
        #region Constructor and Initializations
        
        public My_Application(Window startupWindow)
        {
            InitializeComponent();

            LayoutRoot.Height = System.Windows.SystemParameters.VirtualScreenHeight;
            LayoutRoot.Width = System.Windows.SystemParameters.VirtualScreenWidth;

            mainWindow = startupWindow;
            
            this.Loaded += new RoutedEventHandler(My_Application_Loaded);
        }
                
        private void My_Application_Loaded(object sender, RoutedEventArgs e)
        {
            GisInterfaceMgr bgm = GisInterfaceMgr.Instance;
            bgm.setMainWindow(mainWindow);
            bgm.setOrientation(Orientation.Vertical);

            bgm.setCornerMenusType(CornerMenusMgr.CornerMenuType.FourCornerMenus);

            // Background map is the city of Calgary
            bgm.setBackgroundMapLocation(-114.25, 51.00, -113.88, 51.05);

            // set the list of layers
            bgm.setDefaultMapLayerTypes(getMapLayerTypeList());
            
            // Add GisInterfaceMgr object to the interface
            LayoutRoot.Children.Add(bgm);

            // Listen for when the map layers have been initialized, to add our own
            MapLayersManager.Instance.MapLayersInitialized += onLayerSetup;

        }

        private List<MapLayerDef> getMapLayerTypeList()
        {
            List<MapLayerDef> defaultMapLayers = new List<MapLayerDef>();
            defaultMapLayers.Add(new MapLayerDef(MapLayerDef.MapLayerType.ShadedRelief));
            defaultMapLayers.Add(new MapLayerDef(MapLayerDef.MapLayerType.SatelliteImagery));
            defaultMapLayers.Add(new MapLayerDef(MapLayerDef.MapLayerType.StreetMap));
            defaultMapLayers.Add(new MapLayerDef(MapLayerDef.MapLayerType.OnlinePointAnnotationsLayer, "http://asebeast.cpsc.ucalgary.ca:1892/ArcGIS/rest/services/eGridAnnotations/FeatureServer/0"));
            defaultMapLayers.Add(new MapLayerDef(MapLayerDef.MapLayerType.OnlineLineAnnotationsLayer, "http://asebeast.cpsc.ucalgary.ca:1892/ArcGIS/rest/services/eGridAnnotations/FeatureServer/1"));
            defaultMapLayers.Add(new MapLayerDef(MapLayerDef.MapLayerType.OnlinePolygonAnnotationsLayer, "http://asebeast.cpsc.ucalgary.ca:1892/ArcGIS/rest/services/eGridAnnotations/FeatureServer/2"));

            return defaultMapLayers;
        }

 
        public Window getMainWindow()
        {
            return mainWindow;
        }
        
        
        /// <summary>
        /// Initialize eGrid's customized layers, and set visibility for other MapLayerManager layers.
        /// </summary>
        private void onLayerSetup()
        {
            // Create customized layers for eGrid.
            VehicleLayer VL = new VehicleLayer();
            TroubleTicketServerLayer TTSL = new TroubleTicketServerLayer();

            // Customize visible layers for eGrid.
            LayerCollection MapLayers = MapLayersManager.Instance.MapLayers;

            MapLayers["Imagery"].Visible = false;
            MapLayers["ShadedRelief"].Visible = false;
            MapLayers["BookmarksLayer"].Visible = false;            

        }

        #endregion        
        

    }
}